package com.haochu.xxl.animate;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Transformation;

import com.haochu.xxl.model.PointItem;

/**
 * @author Administrator on 2017-10-1 20:52:09
 * 左右摇头特效动画
 */
public class LRAnimator {
    // 游戏界面view
    private View view;
    // 元素点
    private PointItem point;
    private int len;

    public LRAnimator(View view, PointItem point, int len) {
        this.view = view;
        this.point = point;
        this.len = len;
    }

    public void start() {
        ObjectAnimator animator = ObjectAnimator.ofInt(point, "animIndexLR", 0, len);
        animator.setRepeatCount(ObjectAnimator.INFINITE);
        animator.setRepeatMode(ObjectAnimator.REVERSE);
        animator.setDuration(1000);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                view.postInvalidate();
            }
        });
        animator.start();
    }

}